/*  This file is part of Paxer.

    CASpp is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    CASpp is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with CASpp.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2014 Jérome LAURENS

    See https://code.google.com/p/idalgo/

*/

#ifndef PAXER_DRIVER_HH
# define PAXER_DRIVER_HH
# include <string>
# include <boost/shared_ptr.hpp>
# include <QString>
# include <map>
# include "config.h"
# include <caspp/caspp.h>

// Conducting the whole scanning and parsing of Me.

typedef void * yyscan_t;

PAXER_NS_BEGIN

PAXER_DECLARE_CLASS_REF(Driver);

#warning Is it really a driver ?

class Driver: public CASpp::NodeRefWrap {
public:
    typedef CASpp::NodeRefWrap __super;


    void prepareParse();
    void accept(__super::element_type & theNodeRef);
    __super::element_type & nodeRef();

    Driver();
    virtual ~Driver();
    static void deleteScanner(yyscan_t *scan_p);
    static void deleteBuffer(void *buffer);

    std::map<std::string, int> variables;

    int result;

    // Run the parser.  Return 0 on success.
    int parse (const char *input);
    int parse (const std::string & input);
    int parse (const QString & input);

    // Error handling.
    void error (const int l, const std::string& m) const;
    void error (const std::string& m) const;

    // Options
    bool traceScanning();
    void setTraceScanning(bool yorn);
    bool traceParsing();
    void setTraceParsing(bool yorn);

    const std::string description() const;
    Driver & operator=(const Driver & other); // copy assignment

private:
    bool trace_scanning_m;
    bool trace_parsing_m;
    boost::shared_ptr<void> scanner_m;
};

PAXER_NS_END

#endif // ! PAXER_DRIVER_HH
